package org.example.day20240820;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class GussWord {
    public static void main(String[] args) {
        String[] words = {"banana","elephant","watermelon","apple","monkey","donkey","snake"};
        Random random = new Random();
        int index = random.nextInt(words.length);
        String select_world = words[index];
        System.out.println(select_world);

        char[] charArr = select_world.toCharArray();
        Arrays.fill(charArr, '-');

        int guessTimes = charArr.length+10;
        Scanner scanner = new Scanner(System.in);
        while (guessTimes>0){
            System.out.println(charArr);
            String gussWorld = scanner.nextLine();
            char gussChar = gussWorld.charAt(0);
            if(select_world.contains(gussWorld)){
                for (int i=0; i<select_world.length(); i++){
                    if(select_world.charAt(i) == gussChar){
                        charArr[i] = gussChar;
                    }
                }

            }else {
                guessTimes--;
                System.out.println("you hava"+guessTimes+" times to lose");
            }
            String tmpStr = new String(charArr);
            if(!tmpStr.contains("-")){
                break;
            }
        }
        if(guessTimes>0){
            System.out.println("You Win");
        }else {
            System.out.println("You Lose");
        }
    }
}
